package com.test.demo.micrometer;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Metrics {

    @Autowired
    private MeterRegistry meterRegistry;

    @Bean
    public Counter counter() {
        return Counter.builder("counter").tags("path", "method").description("总数").register(meterRegistry);
    }

    @Bean
    public Gauges gauges() {
        return new Gauges();
    }

    @Bean
    public Gauge Gauge(@Autowired Gauges gauges) {
        return Gauge.builder("value", gauges, Gauges::getValue)
                .description("a simple gauge")
                .tag("tag1", "a")
                .register(meterRegistry);
    }

}
